package service

import (
	"context"
	"github.com/exam/api/request"
	"github.com/exam/model/dao"
)

type IUserService interface {
	Login(ctx context.Context, req request.User) (error, int)
}

type UserService struct {
	dao *dao.UserDao
}

func (u *UserService) Login(ctx context.Context, req request.User) (error, int) {
	Account, err := u.dao.GetUserByAccount(ctx, req.Account)
	if err != nil {
		return err, 0
	}
	if Account.Pwd != req.Pwd {
		return err, 0
	}
	return nil, Account.ID
}

func NewUserService(dao *dao.UserDao) IUserService {
	return &UserService{
		dao: dao,
	}
}
